<!--
/*
 *	Author: José Delgado Pérez
 *	Correo: josedelgado@ula.ve
 *	Fecha: 06/11/2011
 *	Encoding: UTF-8
 */
-->

<?php

/**
 * ARCHIVOS QUE CONTIENE LAS FUNCIONES Y VARIABLES DE CONFIGURACIÓN DE LA APLICACION
 */

#================================================================================#
#VARIABLES
#================================================================================#

$confPorcentaje = Array('1'=>'100%',
                   '0.95'=>'95%',
                   '0.90'=>'90%',
                   '0.85'=>'85%',
                   '0.80'=>'80%',
                   '0.75'=>'75%',
                   '0.70'=>'70%',
                   '0.65'=>'65%',
                   '0.60'=>'60%',
                   '0.55'=>'55%',
                   '0.50'=>'50%',
                   '0.45'=>'45%',
                   '0.45'=>'40%',
                   '0.45'=>'35%',
                   '0.45'=>'30%',
                   '0.45'=>'25%',
                   '0.45'=>'20%',
                   '0.45'=>'15%',
                   '0.45'=>'10%',
                   '0.45'=>'5%',
                   );

#================================================================================#
#FUNCIONES
#================================================================================#
                   
function confOptionPorcentaje($porcentaje=null) {
	global $confPorcentaje;
	foreach($confPorcentaje AS $clave => $valor) {
		echo "<option $selected value=\"$clave\">$valor</option>\n";
	}
}

function mostrarMaterias($cedula, $tabla){
	$DataBase = BD;
	$sql = "SELECT DISTINCT * FROM " . $tabla . " WHERE "; 
	$sql = $sql."cedulaProfesor = '".$cedula."' ";
	$acciones = new AccionProfesor();
	$array = $acciones->consultar($sql,$DataBase);
	foreach($array AS $clave => $valor){

		echo "<tr>".
			 "<td> <input type=\"radio\" name=\"selec\" value=\"".$clave."\" onclick=\"activarEliminar();\" /></td>".
			 "<td><input type=\"text\" disabled=\"disabled\" value=\" ".$valor["nombreMateria"]." \"/></td> ".
			 "<td><input type=\"text\" disabled=\"disabled\" style=\"width: 100px; text-align: center;\" value=\"".$valor["totalHoras"]."\" /></td> ".
			 "<td><input type=\"text\" disabled=\"disabled\" style=\"width: 100px; text-align: center;\" value=\" ".$valor["numSecciones"]."\" /></td> ".
			 "<td><input type=\"text\" disabled=\"disabled\" style=\"width: 100px; text-align: center;\" value=\" ".$valor["cargaAcademica"]." \" /></td> " .
			 "</tr>";	
	}
	return $array;
}

function mostrarTutorias($cedula, $tabla){
	$DataBase = BD;
	$sql = "SELECT DISTINCT * FROM " . $tabla . " WHERE "; 
	$sql = $sql."cedulaProfesor = '".$cedula."' ";
	$acciones = new AccionProfesor();
	$array = $acciones->consultar($sql,$DataBase);
	//var_dump($array);
	foreach($array AS $clave => $valor){
		echo "<tr>".
			 "<td> <input type=\"radio\" name=\"selec\" value=\"".$clave."\" onclick=\"activarEliminarT('".$tabla."');\" /></td>".
			 "<td><input type=\"text\" disabled=\"disabled\" value=\" ".$valor["nombreTesista"]." \"/></td> ".
			 "<td><input type=\"text\" disabled=\"disabled\" style=\"width: 100px; text-align: center;\" value=\"".$valor["cedulaTesista"]."\" /></td> ".
			 "<td><input type=\"text\" disabled=\"disabled\" style=\"width: 100px; text-align: center;\" value=\" ".$valor["tituloTrabajo"]."\" /></td> ".
			 "<td><input type=\"text\" disabled=\"disabled\" style=\"width: 100px; text-align: center;\" value=\" ".$valor["nombreTutor"]." \" /></td> " .
			 "</tr>";	
	}
	return $array;
}


function mostrarSC($cedula, $tabla){
	$DataBase = BD;
	$sql = "SELECT DISTINCT * FROM " . $tabla . " WHERE "; 
	$sql = $sql."cedulaProfesor = '".$cedula."' ";
	$acciones = new AccionProfesor();
	$array = $acciones->consultar($sql,$DataBase);
	//var_dump($array);
	foreach($array AS $clave => $valor){
		echo "<tr>".
			 "<td> <input type=\"radio\" name=\"selec\" value=\"".$clave."\" onclick=\"activarEliminar();\" /></td>".
			 "<td><input type=\"text\" disabled=\"disabled\" value=\"".$valor["nombreTutoriado"]."\" /></td> ".
			 "<td><input type=\"text\" disabled=\"disabled\" style=\"width: 100px; text-align: center;\" value=\"".$valor["cedulaTesista"]."\" /></td> ".
			 "<td><input type=\"text\" disabled=\"disabled\" style=\"width: 100px; text-align: center;\" value=\" ".$valor["proyecto"]."\" /></td> ".
			 "<td><input type=\"text\" disabled=\"disabled\" style=\"width: 100px; text-align: center;\" value=\" ".$valor["comunidad"]." \" /></td> " .
			 "</tr>";	
	}
}


function mostrarCargosAdministrativos($cedula){
	$DataBase = BD;
	$sql = "SELECT DISTINCT t1.actividad, t1.genero, t1.totalHoras FROM 
	cargosAdministrativoas AS t1, cargaAdministrativa AS t2 WHERE 
	  cedulaProfesor = '$cedula' and idCargo = id"; 
	$acciones = new AccionProfesor();
	$array = $acciones->consultar($sql,$DataBase);
	foreach($array AS $clave => $valor){
		echo "<tr>".
			 "<td> <input type=\"radio\" name=\"selec\" value=\"".$clave."\" onclick=\"activarEliminar();\" /></td>".
			 "<td><input type=\"text\" disabled=\"disabled\" style=\"width: 300px;\" value=\" ".$valor["actividad"]." \"/></td> ".
			 "<td><input type=\"text\" disabled=\"disabled\" style=\"width: 150px; text-align: center;\" value=\"".$valor["genero"]."\" /></td> ".
			 "<td><input type=\"text\" disabled=\"disabled\" style=\"width: 50px; text-align: center;\" value=\" ".$valor["totalHoras"]."\" /></td> ".
			 "</tr>";	
	}
	return $array;
}


function mostrarCargosGremiales($cedula){
	$DataBase = BD;
	$sql = "SELECT DISTINCT * FROM cargaGremial WHERE cedulaProfesor = '$cedula'"; 
	$acciones = new AccionProfesor();
	$array = $acciones->consultar($sql,$DataBase);
	foreach($array AS $clave => $valor){
		echo "<tr>".
			 "<td> <input type=\"radio\" name=\"selec\" value=\"".$clave."\" onclick=\"activarEliminar();\" /></td>".
			 "<td><input type=\"text\" disabled=\"disabled\" style=\"width: 300px;\" value=\" ".$valor["cargo"]." \"/></td> ".
			 "<td><input type=\"text\" disabled=\"disabled\" style=\"width: 150px; text-align: center;\" value=\"".$valor["totalHoras"]."\" /></td> ".
			 "</tr>";	
	}
}


function  confCedula($cedula){
	$num = strlen($cedula);
	if($num < 10){
		$numCedula = substr($cedula, 1);
		$nacionalidad = substr($cedula, 0, -($num -1));
		$add = 10 - $num;
		for ($i = 0; $i < $add; $i++){
			$numCedula = '0'.$numCedula;
		}
		$cedula = $nacionalidad.$numCedula;
	}
	return $cedula;
}


function confCargaAcadimicaPregrado($cedula){
	$DataBase = BD;
	$sql = "SELECT DISTINCT * FROM materiasPregrado WHERE "; 
	$sql = $sql."cedulaProfesor = '".$cedula."' ";
	$acciones = new AccionProfesor();
	$array = $acciones->consultar($sql,$DataBase);
	$carga = 0;
	foreach($array AS $clave => $valor){
		$carga = $carga + $valor["cargaAcademica"];
	}
	return $carga;
}


function confCargaAcadimicaPostgrado($cedula){
	$DataBase = BD;
	$sql = "SELECT DISTINCT * FROM materiasPostgrado WHERE "; 
	$sql = $sql."cedulaProfesor = '".$cedula."' ";
	$acciones = new AccionProfesor();
	$array = $acciones->consultar($sql,$DataBase);
	$carga = 0;
	foreach($array AS $clave => $valor){
		$carga = $carga + $valor["cargaAcademica"];
	}
	if($carga > 12) $carga = 12;
	return $carga;
}


function confCargaAcadimicaTutorias($cedula){
	$DataBase = BD;
	$tutorias = Array("tesisPregrado","pasantias","tesisPostgrado");
	foreach ($tutorias as $valor) {
		$sql = "SELECT DISTINCT * FROM ".$valor." WHERE "; 
		$sql = $sql."cedulaProfesor = '".$cedula."' ";
		$acciones = new AccionProfesor();
		$numRegistro = $numRegistro + $acciones->numeroRegistros($sql,$DataBase);
	}
	$cargaAcademica = $numRegistro*3;
	if($cargaAcademica > 9) $cargaAcademica = 9;
	return $cargaAcademica;
}


function confCargaAcadimicaSC($cedula){
	$DataBase = BD;
	$sql = "SELECT DISTINCT * FROM servicioComunitario WHERE "; 
	$sql = $sql."cedulaProfesor = '".$cedula."' ";
	$acciones = new AccionProfesor();
	$numRegistro = $acciones->numeroRegistros($sql,$DataBase);
	$cargaAcademica = $numRegistro*2;
	if($cargaAcademica > 6) $cargaAcademica = 6;
	return $cargaAcademica;
}


function confCargaDocente($cedula){
	$carga = confCargaAcadimicaPregrado($cedula) + confCargaAcadimicaPostgrado($cedula) +
	confCargaAcadimicaSC($cedula) + confCargaAcadimicaTutorias($cedula);
	return $carga;
}


function confInvestigacion($cedula){
	$DataBase = BD;
	$sql = "SELECT DISTINCT * FROM investigacion WHERE "; 
	$sql = $sql."cedulaProfesor = '".$cedula."' ";
	$acciones = new AccionProfesor();
	$array = $acciones->consultar($sql,$DataBase);
	if(!empty($array)){
		foreach($array as $clave => $valor){
			foreach($valor AS $clave1 => $valor1)
	   				$$clave1 = $valor1;
		}
		return Array('totalHoras' => $totalHoras, 'ppi' => $ppi, 
		'pei'  => $pei, 'actividad' => $actividad, 'existe' => true);
	}else{
		return false;
	}		
}


function confCargaInvestigacion($cedula){
	$DataBase = BD;
	$sql = "SELECT DISTINCT * FROM investigacion WHERE "; 
	$sql = $sql."cedulaProfesor = '".$cedula."' ";
	$acciones = new AccionProfesor();
	$array = $acciones->consultar($sql,$DataBase);
	if(!empty($array)){
		foreach($array as $clave => $valor){
			foreach($valor AS $clave1 => $valor1)
	   				$$clave1 = $valor1;
		}
		return $totalHoras;
	}else{
		return 0;
	}
}


function confExtencion($cedula){
	$DataBase = BD;
	$sql = "SELECT DISTINCT * FROM extencion WHERE "; 
	$sql = $sql."cedulaProfesor = '".$cedula."' ";
	$acciones = new AccionProfesor();
	$array = $acciones->consultar($sql,$DataBase);
	if(!empty($array)){
		foreach($array as $clave => $valor){
			foreach($valor AS $clave1 => $valor1)
	   				$$clave1 = $valor1;
		}
		return Array('totalHoras' => $totalHoras, 'actividad' => $actividad, 'numOficio' => $numOficio, 'existe'=> true);
	}else{
		return false;
	}
}


function confCargaExtencion($cedula){
	$DataBase = BD;
	$sql = "SELECT DISTINCT * FROM extencion WHERE "; 
	$sql = $sql."cedulaProfesor = '".$cedula."' ";
	$acciones = new AccionProfesor();
	$array = $acciones->consultar($sql,$DataBase);
	if(!empty($array)){
		foreach($array as $clave => $valor){
			foreach($valor AS $clave1 => $valor1)
	   				$$clave1 = $valor1;
		}
		return $totalHoras;
	}else{
		return 0;
	}
}


function confCargaAdministrativa($cedula){
	$DataBase = BD;
	$sql = "SELECT DISTINCT  t1.totalHoras FROM 
	cargosAdministrativoas AS t1, cargaAdministrativa AS t2 WHERE 
	  cedulaProfesor = '$cedula' and idCargo = id"; 
	$acciones = new AccionProfesor();
	$array = $acciones->consultar($sql,$DataBase);
	$carga  = 0;
	foreach($array AS $clave => $valor){
		$carga = $carga + $valor["totalHoras"];	
	}
	return $carga;
}


function confCargaGremial($cedula){
	$DataBase = BD;
	$sql = "SELECT DISTINCT totalHoras FROM cargaGremial WHERE cedulaProfesor = '$cedula'"; 
	$acciones = new AccionProfesor();
	$array = $acciones->consultar($sql,$DataBase);
	$carga = 0;
	foreach($array AS $clave => $valor){
		$carga = $carga + $valor["totalHoras"];	
	}
	return $carga;
}

?>